import { lazy, Suspense } from 'react';
import Loading from '../Loading';

export type Factory = Parameters<typeof lazy>[0];

export const lazyComponent = (factory: Factory) => {
  const Component = lazy(factory);
  return function (props: Record<string, any>) {
    return (
      <Suspense fallback={<Loading maxContent />}>
        <Component {...props} />
      </Suspense>
    );
  }
}